﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>zl&zcl第一理财平台</title>
    <link type="text/css" rel="stylesheet" href="css/finance.css" />
    <script src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/Util.js"></script>
</head>
<body>
    <h1>理财平台登录页面</h1>
    <div class="myPrdDiv1 text-center padding-30 bg-color">
        <p>
            <label for="username">用户名</label>
            <input id="username" name="username" type="text">
        </p>
        <p>
            <label for="password">密<span class="hiddenFont">空</span>码</label>
            <input id="password" name="password" type="password">
        </p>
        <div class="loginButton">
            <button type="submit" onclick="loginAction()">登录</button>
        </div>
    </div>
    <script>
    /*
    * 初始化登录页面读取json文件放入缓存数据中
    * */
    var sessionData=null;
    $.ajax({
        type:"get",
        url:"data/getJsonData.json",
        async:true,
        success:function(data){
            console.log(data);
            window.localStorage.setItem("sessionData",jsonToStr(data));
        },
        error:function(data){
            alert("数据获取失败，请稍后重试！")
        }
    });
    /*
    * 校验登录信息
    * */
    function loginAction() {
        var userName = $("#username").val();
        var pwd = $("#password").val();
        if(userName==null||userName==""||userName=="undefined"){
            alert("用户名不能为空！")
            return
        }
        if(pwd==null||pwd==""||pwd=="undefined"){
            alert("密码不能为空！")
            return
        }
        var sessionData =strToJson(window.localStorage.getItem("sessionData"));
        var loginFlag = false;
        console.log(sessionData.users)
        $.each( sessionData.users, function(i, value){
            if(value.name==userName){
                if(value.pwd==pwd){
                    window.localStorage.setItem("id_card",value.id);
                    loginFlag=true;
                }
            }
        });
        if (loginFlag) {
            window.location.href = "menuMain.html";
        } else {
            alert("用户名或密码输入错误，请重新输入！")
        }
    }
    </script>
</body>
</html>